package com.xzy.service.impl;

import com.xzy.custom.Page;
import com.xzy.entities.SysUser;
import com.xzy.mapper.SysUserMapper;
import com.xzy.service.SysUserService;

import com.xzy.web.form.SysUserForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * TODO
 *
 * @author XiangZhongyi
 * ClassName: 用户管理业务逻辑类
 * date: 2021/9/20 20:11
 */
@Service
public class SysUserServiceImpl implements SysUserService{

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser findByUserName(String username) {
        return sysUserMapper.findByUserName(username);
    }

    @Override
    public Integer findAllUserInformationCount(Page page,String name) {
        return sysUserMapper.findAllUserInformationCount(page,name);
    }

    @Override
    public List<SysUser> findAllUserInformation(Page page,String name) {
        return sysUserMapper.findAllUserInformation(page,name);
    }

    @Override
    public SysUser findById(Integer id) {
        return sysUserMapper.findById(id);
    }

    @Override
    public void updateById(SysUserForm form,Integer rid) {
        sysUserMapper.updateById(form);
        sysUserMapper.updateUserRoleById(form,rid);
    }

    @Override
    public void updateById(SysUserForm form) {
        sysUserMapper.updateById(form);
    }

    @Override
    public void insert(SysUserForm form) {
        sysUserMapper.insertUser(form);
    }

    @Override
    public void insertUserRole(SysUserForm form, Integer rid) {
        this.insert(form);
        System.out.println("user_id======>"+form.getId()+"user_name=======>"+form.getUsername());
        sysUserMapper.insertUserRole1(form,rid);
    }

    @Override
    public String findNumber() {
        return sysUserMapper.findNumber();
    }

    @Override
    public void delUserInformation(int parseInt) {
        sysUserMapper.delUserRole(parseInt);
        sysUserMapper.delUserInformation(parseInt);
    }

    @Override
    public void updatePwdById(String newpwd, Integer id) {
        sysUserMapper.updatePwdById(newpwd,id);
    }

}
